/*
 * BinaryFile.cpp
 *
 *  Created on: Nov 6, 2013
 *      Author: SG0214746
 */

#include "BinaryFile.h"

BinaryFile::BinaryFile() {
}

BinaryFile::~BinaryFile() {
	close();
}


void BinaryFile::create(const String& path) {
	file.open(path.c_str(), std::fstream::out | std::fstream::trunc | std::fstream::binary);
	file.close();
	file.open(path.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary);
}

bool BinaryFile::open(const String& path, bool createNew) {
	this->path = path;
	if (createNew){
		create(path);
		return true;
	}
	file.open(path.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary);
	if (!file.is_open())
		create(path);
	return true;
}

void BinaryFile::close() {
	if (file.is_open())
		file.close();
}

const String& BinaryFile::getPath() const {
	return path;
}

std::fstream& BinaryFile::getDescriptor() {
	return file;
}
